package main

import "fmt"

func foo() {
	println("call foo")
	bar()
	println("exit foo")
}

func foo2() {
	println("call foo2")
	bar2()
	println("exit foo2")
}

func bar() {
	println("call bar")
	panic("panic occurs in bar")
	zoo()
	println("exit bar")
}

func bar2() {
	println("call bar2")
	defer func() {
		if e := recover(); e != nil {
			fmt.Println("recover the panic:", e)
		}
	}()
	panic("panic occurs in bar2")
	zoo()
	println("exit bar2")
}

func zoo() {
	println("call zoo")
	println("exit zoo")
}

func main() {
	println("call main")
	//foo()
	foo2()
	println("exit main")
}

/*ouput:
call main
call foo
call bar
panic occurs in bar
*/
